<?php
namespace app\blog\controller;

use app\blog\controller\Front;

class Search extends Front
{
    protected function initialize()
    {
        parent::initialize(); 
    }
    
    public function index()
    {
        //SEO标签
        $this->site['searchText'] = $this->query['searchText'];
        $this->site['title'] = $this->seoReplace(config('page.search_title'),true);
        $this->site['keywords'] = xfEmpty(config('page.search_keywords'),$this->query['searchText']);
        $this->site['description'] = $this->seoReplace(config('page.search_description'));
        //分页数据
        if($this->query['searchText']){
            $pageList = $this->pageList($this->query['searchText']);
        }
        //模板赋值
        $this->assign($data);
        $this->assign($pageList);
        $this->assign($this->site);
        //加载模板
        return $this->fetch();
    }

    //分页查询
    private function pageList($searchText='')
    {
        $args = [
            'cache' => config('cache.expire_items'),
            'order' => [
                'detail_id'  => 'desc',
            ],
            'where' => [
                ['detail_name|detail_title|detail_excerpt','like','%'.$searchText.'%'],
                ['detail_status','eq','normal'],
            ],
        ];
        $limit = xfEmpty(config('page.search_limit'),config('channel.limit'));
        //查询数据
        return model('blog/Index','loglic')->allPage($args, intval($limit), $this->site['page'], intval(config('page.search_total')), xfUrlPath('blog/search/index',$this->query));
    }
}